package com.tjp.eight.utils;

import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2017/3/3.
 */

public class StringUtils {
    public static boolean isUrl(String str) {
        boolean isY = isNullOrEmpty(str);
        if (isY)
            return !isY;
        if (str.startsWith("http://") || str.startsWith("https://"))
            return true;
        else
            return false;
    }

    public static boolean isNullOrEmpty(String string) {
        return null == string || string.length() == 0 || string.equals("") || string == "" || string == "0";
    }

    public static boolean isMobileNO(String mobiles) {
        String telRegex = "[1][34578]\\d{9}";
        return isNullOrEmpty(mobiles) ? false : mobiles.matches(telRegex);
    }

    //判断email格式是否正确
    public static boolean isEmail(String email) {
        String str = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
        Pattern p = Pattern.compile(str);
        Matcher m = p.matcher(email);

        return m.matches();
    }

    //判断是否全是数字
    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

    public static String toWan(int input) {
        if (input >= 100000000) {
            double tempD = (double) input / 10000.00d;
            DecimalFormat df = new DecimalFormat("#.00");
            return df.format(tempD) + "亿";
        } else if (input >= 10000) {
            double tempD = (double) input / 10000.00d;
            DecimalFormat df = new DecimalFormat("#.00");
            return df.format(tempD) + "万";
        } else {
            return "" + input;
        }
    }

    public static boolean isW(String input) {
        if (StringUtils.isNullOrEmpty(input)) {
            return true;
        }
        if (input.contains("万") || input.contains("亿")) {
            return true;
        }
        return false;
    }
}
